Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress URI.open warning in Ruby 2.7 #677

Merged
merged 1 commit into from
Sep 17, 2019

Conversation

koic
Copy link
Contributor

@koic koic commented Sep 15, 2019

This PR suppresses the follwoing warning in Ruby 2.7

% ruby -v
ruby 2.7.0dev (2019-09-14T09:21:37Z master 39c37acf86) [x86_64-darwin17]
% bundle exec thor spec
(snip)

/Users/koic/src/github.com/erikhuda/thor/lib/ty
./Users/koic/src/github.com/erikhuda/thor/lib/thor/actions/file_manipulation.rb:89:
warning: calling URI.open via Kernel#open is deprecated, call URI.open directly

cf ruby/ruby@05aac90.

This PR suppresses the follwoing warning in Ruby 2.7

```console
% ruby -v
ruby 2.7.0dev (2019-09-14T09:21:37Z master 39c37acf86) [x86_64-darwin17]
% bundle exec thor spec
(snip)

/Users/koic/src/github.com/erikhuda/thor/lib/ty
./Users/koic/src/github.com/erikhuda/thor/lib/thor/actions/file_manipulation.rb:89:
warning: calling URI.open via Kernel#open is deprecated, call URI.open directly
```

cf ruby/ruby@05aac90.
@koic koic force-pushed the suppress_uri_open_warning_in_ruby27 branch from 373ddb3 to aabc989 Compare September 15, 2019 18:03
require "open-uri"
URI.send(:open, source) { |input| input.binmode.read }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need the send?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It uses send method because this is a private method in Ruby 2.4 and lower.

Ruby 2.5

% ruby -ropen-uri -ve 'URI.open("https://github.com/erikhuda/thor")'
ruby 2.5.6p201 (2019-08-28 revision 67796) [x86_64-darwin17]

Ruby 2.4

% ruby -ropen-uri -ve 'URI.open("https://github.com/erikhuda/thor")'
ruby 2.4.7p357 (2019-08-28 revision 67796) [x86_64-darwin17]
-e:1:in `<main>': private method `open' called for URI:Module (NoMethodError)

@rafaelfranca rafaelfranca merged commit 7591b0e into rails:master Sep 17, 2019
@koic koic deleted the suppress_uri_open_warning_in_ruby27 branch September 17, 2019 16:31
kyanny added a commit to kyanny/sunzi that referenced this pull request Feb 25, 2022
Thor as of v0.20.x relied on `open-uri` that was deprecated since Ruby version 3.
https://github.com/ruby/ruby/blob/v3_0_0/NEWS.md#compatibility-issues

Thor v1.x uses `URI.open` so that it is compatible with Ruby 3.x.
rails/thor#677
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants